package com.study.hot.jetpack.navigation

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.Navigation
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI
import com.study.hot.R
import kotlinx.android.synthetic.main.activity_navigation.*

/** 通过可视化方式管理Fragment切换
 * 1. Navigation Graph:新的资源文件可视化管理Fragment，类似一张地图能够看到各个地点(Destination)以及路线
 * 2. NavHostFragment:当前Fragment容器，类似一辆车
 * 3. NavController:导航的控制这，类似方向盘
 */
class NavigationActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_navigation)
        val navController = Navigation.findNavController(this, R.id.hostFragment)
        val appBarConfiguration = AppBarConfiguration.Builder(bottomNavigationView.menu).build()
        //绑定AppBar
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)
        NavigationUI.setupWithNavController(bottomNavigationView, navController)
    }
}